package com.stone.customview;

import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * @author Stone
 * @version V1.0
 * @description:
 * @date 10/24/18 17:01
 * @email redsstone@163.com
 */
public class Test {

    public static ArrayList<Double> randomHsl(){
        Double H = Math.random();
        Double S = Math.random();
        Double L = Math.random();
        ArrayList<Double> list = new ArrayList<Double>();
        list.add(H);
        list.add(S);
        list.add(L);
        return list;
    }
    public static ArrayList<ArrayList<Double>> getHslArray(){
        ArrayList<ArrayList<Double>> HSL = new ArrayList<ArrayList<Double>>();
        int hslLength = 16;// 获取数量
        for (int i = 0; i < hslLength; i++) {
            ArrayList<Double> ret = randomHsl();
            // 颜色相邻颜色差异须大于 0.25
            if (i > 0 && Math.abs(ret.get(0) - HSL.get(i-1).get(0)) < 0.25) {
                i--;
                continue; // 重新获取随机色
            }
            ret.set(1, 0.7 + (ret.get(1) * 0.2)); // [0.7 - 0.9] 排除过灰颜色
            ret.set(2, 0.4 + (ret.get(2) * 0.4)); // [0.4 - 0.8] 排除过亮过暗色
            // 数据转化到小数点后两位
            DecimalFormat df= new DecimalFormat("######0.00");
            for (int j = 0; j < ret.size(); j++) {
                ret.set(j, Double.parseDouble(df.format(ret.get(j))));
            }
            HSL.add(ret);
        }
        return HSL;
    }
    public static void main(String[] args) {

        System.out.println(getHslArray().toString());
    }

}
